package com.exam.util;

import java.io.File;

import com.exam.dao.UserDao;
import com.exam.entity.User;

import jxl.Sheet;
import jxl.Workbook;

public class ReadExcel {
	
	public static void importExcel(File file) {

		try {
			Workbook book=Workbook.getWorkbook(file);
			Sheet sheet=(Sheet)book.getSheet(0);
			System.out.println("获得Excel数据"+sheet);
			System.out.println("行数："+sheet.getRows());
			System.out.println("列数："+sheet.getColumns());
			UserDao dao = new UserDao();
			for (int i = 1; i < sheet.getRows(); i++) {
				String roleid=sheet.getCell(0,i).getContents();
				int role_id=Integer.parseInt(roleid);
				String classid=sheet.getCell(1,i).getContents();
				int id=Integer.parseInt(classid);
				String name=sheet.getCell(2,i).getContents();
				String password=sheet.getCell(3,i).getContents();
				String phone=sheet.getCell(4,i).getContents();
				String sex=sheet.getCell(5,i).getContents();
				System.out.println(role_id+" "+classid+" "+name+" "+password+" "+phone +" "+sex);
				User user = new User(role_id,id,name,password,phone,sex);
				dao.addUser(user);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
	}
	
}
